/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogoAlineaciones.java
 *
 * Created on 26/01/2013, 10:08:09 PM
 */
package com.camachosanchez.gui;

import com.camachosanchez.bean.Alineaciones;
import com.camachosanchez.bean.DetalleAlineacion;
import com.camachosanchez.bean.Ejes;
import com.camachosanchez.bean.MarcasVehiculo;
import com.camachosanchez.bean.Pilotos;
import com.camachosanchez.bean.TipoAngulo;
import com.camachosanchez.bean.Vehiculos;
import com.camachosanchez.controler.jpa.TipoAnguloJpaController;
import com.camachosanchez.controler.jpa.VehiculosJpaController;
import com.camachosanchez.gui.combo.MyComboBoxEditor;
import com.camachosanchez.gui.combo.MyComboBoxRenderer;
import com.camachosanchez.gui.table.RenderizadorTablaAlineaciones;
import com.camachosanchez.gui.textfield.MaxLengthTextDocument;
import com.camachosanchez.util.Constantes;
import com.camachosanchez.util.GUIUtil;
import com.camachosanchez.util.JPAUtil;
import com.camachosanchez.util.SQLUtil;
import java.awt.Color;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;
import javax.swing.BorderFactory;
import javax.swing.DefaultCellEditor;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;

/**
 *
 * @author Administrador
 */
public class DialogoAlineaciones extends javax.swing.JDialog implements FocusListener {

    private int idUnidad;
    private Vehiculos unidad;
    private DefaultTableModel dm;
    private String[] tipoAlineacion;
    private JTextField txtAngulo;
    private EntityManagerFactory emf;
    private List<Ejes> sistemaEjes;

    /** Creates new form DialogoAlineaciones */
    public DialogoAlineaciones(java.awt.Frame parent, boolean modal, int idUnidad) {
        super(parent, modal);
        initComponents();
        emf = JPAUtil.getEntityManagerFactory();
        this.idUnidad = idUnidad;
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        RenderizadorTablaAlineaciones render = new RenderizadorTablaAlineaciones();
        tblAngulos.setDefaultRenderer(String.class, render);
        tblAngulos.getTableHeader().setReorderingAllowed(false);
        llenarInformacionUnidad();
        establecerEventosTeclas();
        MaxLengthTextDocument docCosto = new MaxLengthTextDocument();
        docCosto.setMaxChars(10, Constantes.DECIMALES);
        txtCosto.setDocument(docCosto);
        txtCosto.setText("0.0");
        selectorFecha.setMaxSelectableDate(new Date());
    }

    private void llenarInformacionUnidad() {
        MaxLengthTextDocument doc_kilometros = new MaxLengthTextDocument();
        doc_kilometros.setMaxChars(15, Constantes.ENTEROS);
        txtKilometraje.setDocument(doc_kilometros);
        txtKilometraje.setText("0");
        VehiculosJpaController vc = new VehiculosJpaController(null);
        unidad = vc.findVehiculos(idUnidad);
        selectorFecha.setDate(new Date());
        if (unidad != null) {
            txtUnidad.setText(unidad.getPlaca().toUpperCase());
            txtCodigo.setText(unidad.getCodBarras().toUpperCase());
            MarcasVehiculo marcaVehiculo = unidad.getIdMarca();
            if (marcaVehiculo != null) {
                txtMarca.setText(marcaVehiculo.getNombre());
            }
            txtModelo.setText(unidad.getIdTipoEje().getNombre());
            txtKilometrajeActual.setText(unidad.getKmActual() + "");
            txtKilometrajeMensual.setText(unidad.getKmRecorridoMensual() + "");
            List<Pilotos> pilotos = new ArrayList<Pilotos>();
            try {
                Query q = JPAUtil.getEntityManagerFactory().createEntityManager().createNamedQuery("Pilotos.findByEstado");
                q.setParameter("estado", true);//lista los activos
                pilotos = q.getResultList();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(Principal.getInstance(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            }
            cmbPiloto.setModel(new DefaultComboBoxModel(pilotos.toArray()));
            TipoAnguloJpaController daoJpaAngulo = new TipoAnguloJpaController(null);
            List<TipoAngulo> listaTiposAngulo = daoJpaAngulo.findTipoAnguloEntities();
            tipoAlineacion = new String[listaTiposAngulo.size()];
            int i = 0;
            for (TipoAngulo tipoAngulo : listaTiposAngulo) {
                tipoAlineacion[i++] = tipoAngulo.getNombre();
            }
            GUIUtil.addEscapeKey(this);
            tblAngulos.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            dm = new DefaultTableModel() {

                @Override
                public boolean isCellEditable(int row, int col) {
                    return col != 0;
                }

                @Override
                public Class getColumnClass(int c) {
                    return String.class;
                }
            };
            Object[] columns = new Object[]{"EJE", "TIPO", "ÁNGULO"};
            dm.setColumnIdentifiers(columns);
            tblAngulos.setModel(dm);
            tblAngulos.setFillsViewportHeight(true);
            tblAngulos.setRowHeight(22);
//            tblAngulos.getColumnModel().getColumn(0).setCellRenderer(tblAngulos.getTableHeader().getDefaultRenderer());

            TableColumn col = tblAngulos.getColumnModel().getColumn(1);
            col.setCellEditor(new MyComboBoxEditor(tipoAlineacion));
            col.setCellRenderer(new MyComboBoxRenderer(tipoAlineacion));
            tblAngulos.getTableHeader().setReorderingAllowed(false);
            DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) tblAngulos.getTableHeader().getDefaultRenderer();
            renderer.setHorizontalAlignment(JLabel.CENTER);
            sistemaEjes = unidad.getIdTipoEje().getEjesList();
            for (Ejes ejes : sistemaEjes) {
                Object[] obj = new Object[3];
                obj[0] = ejes.getIdFuncion().getNombre();
                obj[1] = tipoAlineacion[0];
                obj[2] = "0.0";
                dm.addRow(obj);
            }
            MaxLengthTextDocument docAngulo = new MaxLengthTextDocument();
            docAngulo.setMaxChars(10, Constantes.REALES);
            txtAngulo = new JTextField();
            txtAngulo.setDocument(docAngulo);
            txtCosto.setDocument(docAngulo);
            GUIUtil.SetAnchoColumnas(tblAngulos);
        }
    }

    private void establecerEventosTeclas() {
        TableColumn columnaCodigo = tblAngulos.getColumnModel().getColumn(2);
        txtAngulo.addFocusListener(this);
        txtAngulo.setBorder(BorderFactory.createEmptyBorder());
        txtAngulo.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        txtAngulo.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 3));
        DefaultCellEditor singleclickCodigo = new DefaultCellEditor(txtAngulo);
        singleclickCodigo.setClickCountToStart(1);
        columnaCodigo.setCellEditor(singleclickCodigo);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlBarraHerramientas = new javax.swing.JPanel();
        btnGuardar = new javax.swing.JButton();
        pnlContenedor = new javax.swing.JPanel();
        pnlInformacionBus = new javax.swing.JPanel();
        lblUnidad = new javax.swing.JLabel();
        txtUnidad = new javax.swing.JTextField();
        lblCodigo = new javax.swing.JLabel();
        txtCodigo = new javax.swing.JTextField();
        lblMarca = new javax.swing.JLabel();
        txtMarca = new javax.swing.JTextField();
        lblModelo = new javax.swing.JLabel();
        txtModelo = new javax.swing.JTextField();
        lblKilometrajeActual = new javax.swing.JLabel();
        txtKilometrajeActual = new javax.swing.JTextField();
        lblKilometrajeMensual = new javax.swing.JLabel();
        txtKilometrajeMensual = new javax.swing.JTextField();
        pnlInformacion = new javax.swing.JPanel();
        lblFecha = new javax.swing.JLabel();
        selectorFecha = new com.toedter.calendar.JDateChooser();
        lblPiloto = new javax.swing.JLabel();
        cmbPiloto = new javax.swing.JComboBox();
        lblKilometraje = new javax.swing.JLabel();
        txtKilometraje = new javax.swing.JTextField();
        pnlTabla = new javax.swing.JPanel();
        scrTabla = new javax.swing.JScrollPane();
        tblAngulos = new javax.swing.JTable();
        txtCosto = new javax.swing.JTextField();
        lblCosto = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(".:: Alineación de Neumáticos ::.");

        pnlBarraHerramientas.setBackground(new java.awt.Color(255, 255, 255));
        pnlBarraHerramientas.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        pnlBarraHerramientas.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/24_save.png"))); // NOI18N
        btnGuardar.setToolTipText("Guardar");
        btnGuardar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnGuardar.setMaximumSize(new java.awt.Dimension(22, 22));
        btnGuardar.setMinimumSize(new java.awt.Dimension(22, 22));
        btnGuardar.setPreferredSize(new java.awt.Dimension(22, 22));
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });
        pnlBarraHerramientas.add(btnGuardar);

        getContentPane().add(pnlBarraHerramientas, java.awt.BorderLayout.PAGE_START);

        pnlInformacionBus.setBorder(javax.swing.BorderFactory.createTitledBorder("Información de la unidad"));
        pnlInformacionBus.setLayout(new java.awt.GridLayout(2, 6, 5, 5));

        lblUnidad.setText("Número de placa:");
        pnlInformacionBus.add(lblUnidad);

        txtUnidad.setEditable(false);
        pnlInformacionBus.add(txtUnidad);

        lblCodigo.setText("Código:");
        pnlInformacionBus.add(lblCodigo);

        txtCodigo.setEditable(false);
        pnlInformacionBus.add(txtCodigo);

        lblMarca.setText("Marca:");
        pnlInformacionBus.add(lblMarca);

        txtMarca.setEditable(false);
        pnlInformacionBus.add(txtMarca);

        lblModelo.setText("Modelo:");
        pnlInformacionBus.add(lblModelo);

        txtModelo.setEditable(false);
        pnlInformacionBus.add(txtModelo);

        lblKilometrajeActual.setText("Kilometraje actual:");
        pnlInformacionBus.add(lblKilometrajeActual);

        txtKilometrajeActual.setEditable(false);
        pnlInformacionBus.add(txtKilometrajeActual);

        lblKilometrajeMensual.setText("Kilometraje mensual:");
        pnlInformacionBus.add(lblKilometrajeMensual);

        txtKilometrajeMensual.setEditable(false);
        pnlInformacionBus.add(txtKilometrajeMensual);

        pnlInformacion.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        lblFecha.setText("Fecha:");

        selectorFecha.setDateFormatString("dd/MM/yyyy");

        lblPiloto.setText("Piloto:");

        cmbPiloto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        lblKilometraje.setText("Kilometraje:");

        txtKilometraje.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtKilometraje.setText("0.0");

        javax.swing.GroupLayout pnlInformacionLayout = new javax.swing.GroupLayout(pnlInformacion);
        pnlInformacion.setLayout(pnlInformacionLayout);
        pnlInformacionLayout.setHorizontalGroup(
            pnlInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInformacionLayout.createSequentialGroup()
                .addComponent(lblFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(selectorFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cmbPiloto, javax.swing.GroupLayout.PREFERRED_SIZE, 248, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblKilometraje, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(5, 5, 5)
                .addComponent(txtKilometraje, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE))
        );
        pnlInformacionLayout.setVerticalGroup(
            pnlInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInformacionLayout.createSequentialGroup()
                .addGroup(pnlInformacionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(lblFecha, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(selectorFecha, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblKilometraje, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lblPiloto, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cmbPiloto)
                    .addComponent(txtKilometraje))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pnlTabla.setLayout(new java.awt.BorderLayout());

        tblAngulos.setBackground(new java.awt.Color(240, 240, 240));
        tblAngulos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        scrTabla.setViewportView(tblAngulos);

        pnlTabla.add(scrTabla, java.awt.BorderLayout.CENTER);

        txtCosto.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtCosto.setText("0.0");

        lblCosto.setFont(new java.awt.Font("Tahoma", 1, 11));
        lblCosto.setText("Costo:");

        javax.swing.GroupLayout pnlContenedorLayout = new javax.swing.GroupLayout(pnlContenedor);
        pnlContenedor.setLayout(pnlContenedorLayout);
        pnlContenedorLayout.setHorizontalGroup(
            pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlContenedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlTabla, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 705, Short.MAX_VALUE)
                    .addComponent(pnlInformacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlInformacionBus, javax.swing.GroupLayout.DEFAULT_SIZE, 705, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlContenedorLayout.createSequentialGroup()
                        .addComponent(lblCosto, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtCosto, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        pnlContenedorLayout.setVerticalGroup(
            pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlContenedorLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(pnlInformacionBus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlInformacion, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlTabla, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtCosto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCosto))
                .addContainerGap())
        );

        getContentPane().add(pnlContenedor, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
        // TODO add your handling code here:
        if (tblAngulos.getCellEditor() != null) {
            tblAngulos.getCellEditor().stopCellEditing();
        }
        guardar();
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void guardar() {
        if (validarDatos()) {
            EntityManager em = null;
            try {
                em = emf.createEntityManager();
                em.getTransaction().begin();
                Alineaciones alineacion = new Alineaciones();
                alineacion.setFecha(selectorFecha.getDate());
                try {
                    alineacion.setKmVehiculo(Integer.parseInt(txtKilometraje.getText()));
                } catch (NumberFormatException e) {
                    JOptionPane.showMessageDialog(this, "El kilometraje ingresado no es correcto.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
                    txtKilometraje.requestFocusInWindow();
                    return;
                }
                try {
                    alineacion.setCosto(Double.parseDouble(txtCosto.getText()));
                } catch (NumberFormatException e) {
                    JOptionPane.showMessageDialog(this, "El costo ingresado no es correcto.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
                    txtCosto.requestFocusInWindow();
                    return;
                }
                alineacion.setNroEjes((short) sistemaEjes.size());
                alineacion.setIdVehiculos(unidad);
                alineacion.setIdPilotos((Pilotos) cmbPiloto.getSelectedItem());
                alineacion.setIdUsuarios(Constantes.currentUser);
                List<DetalleAlineacion> detalle = new ArrayList<DetalleAlineacion>();
                int tam = dm.getRowCount();
                for (int i = 0; i < tam; i++) {
                    DetalleAlineacion item = new DetalleAlineacion();
                    item.setIdFuncionEje(sistemaEjes.get(i).getIdFuncion());
                    String nombreAngulo = dm.getValueAt(i, 1).toString();
                    TipoAngulo tipoAangulo = SQLUtil.buscarPorNombreAngulo(nombreAngulo);
                    item.setIdTipoAngulo(tipoAangulo);
                    BigDecimal angulo;
                    try {
                        angulo = BigDecimal.valueOf(Double.valueOf(dm.getValueAt(i, 2).toString()));
                    } catch (NumberFormatException ex) {
                        JOptionPane.showMessageDialog(this, "El valor del ángulo en la fila " + (i + 1) + " no es el correcto.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
                        return;
                    }
                    item.setAngulo(angulo);
                    detalle.add(item);
                }

                for (DetalleAlineacion d : detalle) {
                    d.setIdAlineacion(alineacion);
                }
                alineacion.setDetalleAlineacionList(detalle);
                em.persist(alineacion);
                em.flush();
                em.refresh(alineacion);
                em.getTransaction().commit();
                JOptionPane.showMessageDialog(this, "El registro de alineación de neumáticos ha finalizado correctamente.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
                dispose();

            } catch (Exception e) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                JOptionPane.showMessageDialog(Principal.getInstance(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            } finally {
                if (em != null) {
                    em.close();
                }
            }
        }
    }

    private boolean validarDatos() {
        if (selectorFecha.getDate() == null) {
            JOptionPane.showMessageDialog(this, "Ingrese una fecha válida.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            selectorFecha.requestFocusInWindow();
            return false;
        }
        if ((txtKilometraje.getText()).equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese un kilometraje válido.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtKilometraje.requestFocusInWindow();
            return false;
        }
        if ((txtCosto.getText()).equals("")) {
            JOptionPane.showMessageDialog(this, "Ingrese un costo total para la alineación.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtCosto.requestFocusInWindow();
            return false;
        }
        if (selectorFecha.getDate().after(new Date())) {
            JOptionPane.showMessageDialog(this, "La fecha no puede ser posterior a la fecha actual.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            return false;
        }
        return true;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnGuardar;
    private javax.swing.JComboBox cmbPiloto;
    private javax.swing.JLabel lblCodigo;
    private javax.swing.JLabel lblCosto;
    private javax.swing.JLabel lblFecha;
    private javax.swing.JLabel lblKilometraje;
    private javax.swing.JLabel lblKilometrajeActual;
    private javax.swing.JLabel lblKilometrajeMensual;
    private javax.swing.JLabel lblMarca;
    private javax.swing.JLabel lblModelo;
    private javax.swing.JLabel lblPiloto;
    private javax.swing.JLabel lblUnidad;
    private javax.swing.JPanel pnlBarraHerramientas;
    private javax.swing.JPanel pnlContenedor;
    private javax.swing.JPanel pnlInformacion;
    private javax.swing.JPanel pnlInformacionBus;
    private javax.swing.JPanel pnlTabla;
    private javax.swing.JScrollPane scrTabla;
    private com.toedter.calendar.JDateChooser selectorFecha;
    private javax.swing.JTable tblAngulos;
    private javax.swing.JTextField txtCodigo;
    private javax.swing.JTextField txtCosto;
    private javax.swing.JTextField txtKilometraje;
    private javax.swing.JTextField txtKilometrajeActual;
    private javax.swing.JTextField txtKilometrajeMensual;
    private javax.swing.JTextField txtMarca;
    private javax.swing.JTextField txtModelo;
    private javax.swing.JTextField txtUnidad;
    // End of variables declaration//GEN-END:variables

    @Override
    public void focusGained(FocusEvent e) {
        if (e.getSource() == txtAngulo) {
            txtAngulo.setBackground(new Color(255, 251, 170));
            txtAngulo.requestFocusInWindow();
            txtAngulo.setEditable(true);
            txtAngulo.selectAll();
        }
    }

    @Override
    public void focusLost(FocusEvent e) {
    }
}
